//
//  JMyCollectView.m
//  HeadIndustry
//
//  Created by jun on 2017/9/13.
//  Copyright © 2017年 jun. All rights reserved.
//

#import "JMyCollectView.h"
#import "UITableView+JFTableView.h"
#import "JCollectShopCell.h"

@interface JMyCollectView()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;

@end

@implementation JMyCollectView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        
        self.backgroundColor = [UIColor whiteColor];
        self.opaque = NO;
        [self setUpView];
    }
    return  self;
}

- (void)setUpView {
    
    UITableView *tableView = [UITableView initWithTableView:CGRectMake(0, 0, self.width, self.height) withDelegate:self];
    tableView.rowHeight = 80;
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self addSubview:tableView];
    [tableView registerClass:[JCollectShopCell class] forCellReuseIdentifier:NSStringFromClass([JCollectShopCell class])];
    _tableView = tableView;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    JCollectShopCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([JCollectShopCell class]) forIndexPath:indexPath];
    cell.verdorModel = _dataArr[indexPath.row];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    JVendorModel *model = _dataArr[indexPath.row];
    if (self.delegate && [self.delegate respondsToSelector:@selector(selCellShop:verdorModel:)]) {
        [self.delegate selCellShop:indexPath verdorModel:model];
    }
}

- (void)setDataArr:(NSArray *)dataArr
{
    _dataArr = dataArr;
    [self.tableView reloadData];
}

@end
